using Sinacor.Servico.Bovespa.ManutencaoOrdens.Service.ServiceContract;
using System.Collections.Generic;
using Sinacor.Infra.Service.Security.Services;

namespace Sinacor.Servico.Bovespa.ManutencaoOrdens.Service.ServiceImplementation
{
    [SinacorServiceBehavior]
	public class Justificativa : IJustificativa
    {

        #region Construtor
        public Justificativa(){ }
        #endregion

        #region Metodos

        /// <summary>Consulta as justificativas de uma determinada ordem</summary>
        /// <tables>TORJUSD,TORMOVD,TSCCLIBOL,TORCTRL_JUSD</tables>
        /// <param name="parameter">ChaveOrdemRequest</param>
        /// <returns>Lista de JustificativaResponse</returns>
		public List<DataContract.Response.JustificativaResponse> ConsultarJustificativas(DataContract.Request.ChaveOrdemRequest request)
        {
            Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa transIn =
                new Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa();

            Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.BusinessEntityToDataContract.Justificativa transOut =
                new Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.BusinessEntityToDataContract.Justificativa();

            BusinessLogic.Justificativa justificativa = new BusinessLogic.Justificativa();

            return transOut.ToJustificativaResponse(justificativa.ConsultarJustificativas(transIn.ToChaveOrdem(request)));
		}

        /// <summary>Consulta a justificativa de uma determinada ordem</summary>
        /// <tables>TORJUSD,TORMOVD,TSCCLIBOL,TORCTRL_JUSD</tables>
        /// <returns>Lista de JustificativaResponse</returns>
        public DataContract.Response.JustificativaResponse ObterJustificativa(DataContract.Request.FiltroJustificativa request)
        {
            Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa translatorRequest =
                new Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa();
            Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.BusinessEntityToDataContract.Justificativa translatorResponse =
                new Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.BusinessEntityToDataContract.Justificativa();

            BusinessLogic.Justificativa justificativa = new BusinessLogic.Justificativa();

            return translatorResponse.ToJustificativaResponse(justificativa.ObterJustificativa(translatorRequest.ToFiltroJustificativa(request)));
        }

        /// <summary>
        /// Altera justificativa
        /// </summary>
        /// <param name="request"></param>
        public void AlterarJustificativa(Sinacor.Servico.Bovespa.ManutencaoOrdens.Service.DataContract.Request.JustificativaRequest request)
        {
            Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa translator =
                new Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa();
            BusinessLogic.Justificativa blJustificativa = new BusinessLogic.Justificativa();

            blJustificativa.AlterarJustificativa(translator.ToJustificativa(request));
        }

        /// <summary>
        /// Altera justificativas
        /// </summary>
        /// <param name="request"></param>
        public void AlterarJustificativas(List<Sinacor.Servico.Bovespa.ManutencaoOrdens.Service.DataContract.Request.JustificativaRequest> request)
        {
            Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa translator =
                new Sinacor.Servico.Bovespa.ManutencaoOrdens.ServiceImplementation.Translator.DataContractToBusinessEntity.Justificativa();
            BusinessLogic.Justificativa blJustificativa = new BusinessLogic.Justificativa();

            blJustificativa.AlterarJustificativas(translator.ToJustificativa(request));
        }

        #endregion
    }

}